<template>
	<view>
		<u-navbar v-if="!$isWeixin()" :title="title" :titleWidth="450" :titleBold="true" :background="{ backgroundColor: '#ffffff' }" :is-fixed="true"></u-navbar>

		<u-tabs active-color="#FF7A23" :list="tabList" :current="tabIndex" @change="index => (tabIndex = index)"></u-tabs>

		<view class="" v-if="tabIndex == 0"><relations :list="state.Dealer_RelationList"></relations></view>

		<view class="" v-if="tabIndex == 1">
			<basic-information
				v-if="state.ShowLevel == 1"
				:metadata="state.DataBaseInfo"
				:showOtherInfo="false"
				:showReview="false"
				:showGrade="false"
				:showParent="false"
				:loadCity="loadCity"
				:data="{
					Dealer_BaseInfo: state.First_Dealer_BaseInfo
				}"
			></basic-information>

			<block v-if="state.ShowLevel == 2">
				<u-cell-item title="一级经销商名称" :arrow="false" :value="state.First_Dealer_BaseInfo.Name" :border-bottom="false"></u-cell-item>
				<basic-information
					:metadata="state.DataBaseInfo"
					:showOtherInfo="false"
					:showReview="false"
					:showGrade="false"
					:showParent="false"
					:loadCity="loadCity"
					:data="{
						Dealer_BaseInfo: state.Double_Dealer_BaseInfo
					}"
				></basic-information>
			</block>

			<block v-if="state.ShowLevel == 3">
				<u-cell-item title="一级经销商名称" :arrow="false" :value="state.First_Dealer_BaseInfo.Name"></u-cell-item>
				<u-cell-item title="二级经销商名称" :arrow="false" :value="state.Double_Dealer_BaseInfo.Name" :border-bottom="false"></u-cell-item>
				<store-information :loadCity="loadCity" :data="state.Door_Dealer_BaseInfo"></store-information>
			</block>
		</view>

		<view class="" v-if="tabIndex == 2">
			<outdoor-apply v-for="(item, index) in state.OutdoorSuitsDetail" :selectType="4" :key="index" :value="item" :index="index"></outdoor-apply>
		</view>

		<view class="" v-if="tabIndex == 3">
			<u-cell-item title="申请时间" :arrow="false" :value="state.ApplicationDate | date('yyyy-mm-dd hh:MM')"></u-cell-item>
			<u-cell-item title="门头照片" :arrow="false" :border-bottom="false" style="padding-bottom: 0;"></u-cell-item>
			<u-cell-item :arrow="false" v-if="state.ApplyForPhoto">
				<image-upload
					:readonly="true"
					:value="
						state.ApplyForPhoto.split(',').map(item => {
							return {
								Value: item
							};
						})
					"
				></image-upload>
			</u-cell-item>
		</view>

		<view class="" v-if="tabIndex == 4">
			<u-cell-item title="门头照片" :arrow="false" :border-bottom="false" style="padding-bottom: 0;"></u-cell-item>
			<u-cell-item :arrow="false" v-if="state.CompletionPhoto">
				<image-upload
					:readonly="true"
					:value="
						state.CompletionPhoto.split(',').map(item => {
							return {
								Value: item
							};
						})
					"
				></image-upload>
			</u-cell-item>
		</view>

		<view class="btn-group-fixed"><u-button @tap="backToList">返回列表</u-button></view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			title: '户外套装审核详情',

			tabList: [{ name: '销售业务关系' }, { name: '基本信息' }, { name: '户外套装申请' }, { name: '申请照片' }, { name: '验收照片' }],
			tabIndex: 0,

			DealerId: 8913,
			SelectType: 4,
			ModultPrototypeAuditId: 10191,
			
			loadCity: false,

			state: {
				ApplicationDate: null,
				ApplicationRemake: '',
				ApplyForPhoto: '',
				CompletionPhoto: '',
				DataBaseInfo: {},
				Dealer_RelationList: [],
				DoorHandleInfo: {},
				DoorPhotoList: [],
				Door_Dealer_BaseInfo: {},
				Double_Dealer_BaseInfo: {},
				EntityPrototypeDetail: [],
				FinalAuditNote: '',
				FirstAuditNote: '',
				First_Dealer_BaseInfo: {},
				LogisticsList: [],
				ModuleDetail: [],
				ModultMedalsDetail: [],
				OutdoorSuitsDetail: [],
				ReviewAuditNote: '',
				ShellPrototypeDetail: [],
				ShowLevel: null,
				StateName: '',
				State: null
			}
		};
	},

	onLoad(options) {
		if (options.DealerId) {
			this.DealerId = options.DealerId;
		}
		if (options.ModultPrototypeAuditId) {
			this.ModultPrototypeAuditId = options.ModultPrototypeAuditId;
		}
		this.init();

		if (this.$isWeixin()) {
			this.$setTitle(this.title);
		}
	},

	methods: {
		backToList() {
			uni.navigateBack()
		},

		init() {
			this.$u.api
				.getModuleDetail({
					DealerId: this.DealerId,
					SelectType: this.SelectType,
					ModultPrototypeAuditId: this.ModultPrototypeAuditId
				})
				.then(res => {
					console.log(res);
					const { ResultCode, ResultData } = res;
					if (ResultCode === 1) {
						this.state = ResultData;
						this.loadCity = true;

						this.state.OutdoorSuitsDetail.forEach(item => {
							item.ApplyList.forEach(apply => {
								this.getProductList(apply.BrandId, 4).then(res => {
									apply.ProductBaseList = res;
								});
							});
						});
					}
				});
		},

		getProductList(brandId, selectType) {
			return new Promise((relove, reject) => {
				this.$u.api
					.getProductDic({
						SelectType: selectType,
						BrandId: brandId
					})
					.then(res => {
						console.log(res);
						const { ResultCode, ProductList, T_ProductList } = res;
						if (ResultCode === 1) {
							const list = [];
							list.push(...ProductList);
							list.push(...T_ProductList);
							relove(list);
						}
					});
			});
		}
	}
};
</script>

<style></style>
